import { computed, watchEffect, watch } from "vue";
import { useUserStore } from "@/store/modules/user";
import router from "@/router";

export default function (dataCallBack?: (data?: any) => any) {
  const userPlantInfo = computed(() =>
    useUserStore().userPlantInfo ? JSON.parse(useUserStore().userPlantInfo) : {}
  );
  watch(
    () => userPlantInfo.value,
    (newValue) => {
      // console.log("更新默认工厂", newValue);
      router.go(0);
      // if (newValue?.id) {
      //   dataCallBack && dataCallBack(newValue?.id);
      // }
    }
  );
  // 把方法和数据返回出去
  return {
    userPlantInfo,
  };
}
